<template>
	<view class="warpper">
		<view class="logo">
			<image src="../../static/assets/img/logo_01.png" mode="widthFix"></image>
		</view>
		<view class="title">
			外来车辆登记管理
		</view>
		<view class="person">
			<image src="../../static/assets/img/person_01.png" mode="widthFix"></image>
			<input type="text" value="" placeholder="请输入用户名" v-model="person" />
		</view>
		<view class="pass">
			<image src="../../static/assets/img/password_01.png" mode="widthFix"></image>
			<input type="password" value="" placeholder="请输入密码" v-model="password" />
		</view>
		<van-button type="info" class="carNumberBtn" @tap.native="submitNumber">登录</van-button>
	</view>
</template>

<script>
	import util from './../../utils/util.js';
	import api from './../../utils/api.js';
	import {
		encryptedData
	} from './../../utils/config.js';
	export default {
		data() {
			return {
				person: '',
				password: ''
			}
		},
		onLoad() {
			if(uni.getStorageSync('loginName') && uni.getStorageSync('password')){
				this.setData({
					person:uni.getStorageSync('loginName'),
					password:uni.getStorageSync('password'),
				})
				uni.showLoading({
					title: '登录中...'
				});
				this.submitNumber()
			}
		},
		methods: {
			submitNumber() {
				var _this = this
				if (_this.person == '') {
					uni.showToast({
						title: '请输入用户名',
						icon: 'none'
					})
					return
				}
				if (_this.password == '') {
					uni.showToast({
						title: '请输入密码',
						icon: 'none'
					})
					return
				}
				uni.showLoading({
					title: '加载中'
				});
				let param = {
					loginName: encryptedData(_this.person),
					password: encryptedData(_this.password)
				}
				util.request(api.pmLogin, param, 'POST')
					.then((res) => {
						console.log(res)
						uni.hideLoading();
						if (res.success) {
							uni.navigateTo({
								url: '../personlicenses/personlicenses'
							})
							uni.setStorageSync('loginName', _this.person)
							uni.setStorageSync('password', _this.password)
						} else {
							uni.showToast({
								title: res.msg,
								icon: 'none'
							});
						}
					})

			}
		}
	}
</script>

<style>
	@import './personLogin.css';
</style>
